<script type="text/javascript">
$(function(){
	array=[];//清空数组
	$.get("makeCard/getCardInfo",function(data){
		var content="<option value='' selected>请选择</option>";
		$(data).each(function(n,item){
				for(i=0;i<item.cdProDefinitions.length;i++){
				content+="<option value="+item.cdProDefinitions[i].cardpCode+">"
				+item.cdProDefinitions[i].cardpName+"</option>"
			};
			$("#cardCodeSingleTask").html(content);
		});	
	},"json");
	$.post("tellerManage/getpaperAndBranch",function(json){
		 var contentb="<option value='' >请选择</option>";
		 $(json).each(function(n,item){
			for(i=0;i<item.branchs.length;i++){
				contentb+="<option value="+item.branchs[i].orgName+">"
				+item.branchs[i].orgName+"</option>"
			};
			$("#netDotByMakeCardSingle").html(contentb);
		 });
		
	 },"json")
	$.ajax({
		type: 'POST',
		url:"makeCardBlank/getSingleMakeCardInfo",
		dataType:"json",
		cache: false,
		success: getSingleTaskInfo,//回调函数
		error: DWZ.ajaxError
	});
	
});
//去修改页面
function updateSingleTask(){
	if($("input[name='singletasked']:checked").length < 1){
		 alertMsg.warn("您未选择数据！")
		 return false;
	 }
	if($("input[name='singletasked']:checked").length >= 2){
		 alertMsg.warn("不能选择多于1条数据！")
		 return false;
	 }
	var parm="";
	var array;
	$("input[name='singletasked']:checked").each(function(n,item){
		array=$(this).val().split("#")
		//alert(array);
		parm=array[0];
	})	
	var options={"width":"400","height":"300","param":parm};//+parm
	$.pdialog.open("makeCardBlank/goUpdateMakeCardTask","infos", "详细信息",options);
}
//删除信息
function deleteSingleTask(){
	if($("input[name='singletasked']:checked").length < 1){
		 alertMsg.warn("您未选择数据！")
		 return false;
	 }
	var parm="";
	var array;
	$("input[name='singletasked']:checked").each(function(n,item){
		array=$(this).val().split("#");
		parm+=array[0]+","
	})
	alertMsg.confirm("是否确定", {
    		okCall: function(){
    			$.post("makeCardBlank/deleteSingleTask",{parm:parm}, refreshSingleTask,"json")
    		}
    	});
	//alert(parm)
	//$.post("makeCardBlank/deleteSingleTask",{parm:parm}, refreshSingleTask,"json")
}
//检验复选框-----------------------------------------------------------
function validateChechBox3(){
	var len=array.length;
	if(len==0){
		alertMsg.warn("您未选择数据！")
		 return false;
	}
	if(len>=2){
		for(var i=0;i<array.length;i++){
			var currentCardP=array[i].split("#")[2];
			var nextCardP=array[i+1].split("#")[2];
			var currentCardT=array[i].split("#")[3];
			var nextCardT=array[i+1].split("#")[3];
			if(currentCardP!=nextCardP){
				alertMsg.warn("您选择的卡产品不同");
				return false;
			}
			if(currentCardT!=nextCardT){
				alertMsg.warn("您选择的卡物理类型不同");
				return false;
			}
		} 
	}
/* 	  var length =$("input[name='singletasked']:checked").length;
	 if(length >= 2){
		 for(var i=0;i<length;i++){
			var currentCardP=$("input[name='singletasked']:checked:eq("+i+")").parent().parent().find("td:eq(3)").text();
			var nextCardP=$("input[name='singletasked']:checked:eq("+(i+1)+")").parent().parent().find("td:eq(3)").text();
			var currentCardT=$("input[name='singletasked']:checked:eq("+i+")").parent().parent().find("td:eq(4)").text();
			var nextCardT=$("input[name='singletasked']:checked:eq("+(i+1)+")").parent().parent().find("td:eq(4)").text();
			if(nextCardP==""||nextCardT==""){
				//alert("都已经比对完成了")
				return  true;
			}
			if(currentCardP!=nextCardP){
				alertMsg.warn("您选择的卡产品不同");
				return false;
			}
			if(currentCardT!=nextCardT){
				alertMsg.warn("您选择的卡物理类型不同");
				return false;
			}
			
		 }
	 } */ 
	return true;
}
//单笔任务导出--------------------------------------------------------------------
function commitFormExportTaskSingle(form){
	$form=$(form);
	 if (!$form.valid()) {
			return false;
		} 
	$.ajax({
		url:$form.attr("action"),
		 dataType:'json',
		 type:"post",
	 	 traditional:true,
	 	 data:{
	 		 "array":array,
	 	 },
	 	success:refreshSingleTask
	})
	return false;
}

function downloadFileByForm(fileName) {
	console.log('进入方法'+fileName)
    var url = "/makeCardBlank/download/bjm?t= "+ new Date().getTime();
    var form = $("<form></form>").attr("action", url).attr("method", "post").attr("target", "_blank");
    form.append($("<input></input>").attr("type", "hidden").attr("name", "fileName").attr("value", fileName));
    
    form.appendTo('body').submit().remove();
    alert("提交完成请求")
}


//导出任务刷新页面-----------------------------------------------------------------
function refreshSingleTask(json){
	$(json).each(function(n,item){
		var paths = item.paths
		
		
		if(item.statusCode=="200"){
			alertMsg.correct(item.message);
			array=[];//清空数组
			$.ajax({
				type: 'POST',
				url:"makeCardBlank/getSingleMakeCardInfo",
				data:$("#pagerForm").serialize(),
				dataType:"json",
				cache: false,
				success: getSingleTaskInfo,//回调函数
				error: DWZ.ajaxError
			});
		}else if(item.statusCode=="300"){
			alertMsg.warn(json.message);
		}
		for(var i in paths){
			console.log(paths[i])
			window.open( paths[i])
		}
		
		
// 		for(var i in fileNames){
			
// 			var fileName = fileNames[i]
// 			console.log(fileName)
// // 			downloadFileByForm(fileName,i)

// 			var url = "/makeCardBlank/download/bjm?t= "+ new Date().getTime();
// 		    var form = $("<form></form>").attr("action", url).attr("method", "post").attr("target", "_blank");
// 		    form.append($("<input></input>").attr("type", "hidden").attr("name", "fileName").attr("value", fileName));
// 		    form.appendTo('body').submit().remove();
// 				alert(url)
// 		}
		
// 		$("form #0").submit()
// 		$("form #1").submit()
		
		
	});
	
	
};
</script>

<div class="pageHeader ">
	<form id="pagerForm" method="post"
		action="makeCardBlank/getSingleMakeCardInfo"
		class="pageForm required-validate"
		onsubmit="return validateCallback(this,getSingleTaskInfo);">
		<input type="hidden" name="pageNum" value="" /> <input type="hidden"
			name="numPerPage" value="" />
		<!-- <input type="hidden" name="pageCount" value="" /> -->
		<div class="searchBar">
			<!-- <table class="searchContent">
			<tr>
				<td style="text-align:left"><label>卡产品：</label></td>
				<td style="text-align:left"><select id="cardCodeSingleTask" name="cardPCode" class="">
			
				</select></td>
			
				<td style="text-align:left"><label>网点：</label></td>
				<td style="text-align:left"><input  name="netDot" class="" type="text" size="30"  alt="请输入……"/></td>
			</tr>
			<tr>
				<td><label>任务生成日期(起)：</label></td>
				<td><input  name="startDate" class="date" type="text" size="30"  /></td>
			
				<td><label>任务生成日期(止)：</label></td>
				<td><input  name="endDate" class="date" type="text" size="30" /></td>
			</tr>
			</table> -->
			<div class="row" style="padding: 0 10px;">
				<div class="col-md-6 col-sm-12">
					<p>
						<label>卡产品：</label> <select id="cardCodeSingleTask"
							name="cardPCode" class=""></select>
					</p>
				</div>
				<div class="col-md-6 col-sm-12">
					<p>
						<label>网点：</label> <select id="netDotByMakeCardSingle" name="netDot"></select>
					</p>
				</div>
			</div>
			<div class="row" style="padding: 0 10px;">
				<div class="col-md-6 col-sm-12">
					<p>
						<label>任务生成日期(起)：</label><input name="startDate" class="date validDateFrom"
							type="text" size="30" />
					</p>
				</div>
				<div class="col-md-6 col-sm-12">
					<p>
						<label>任务生成日期(止)：</label><input name="endDate" class="date validDateTo"
							type="text" size="30" />
					</p>
				</div>
			</div>
			<div class="subBar">
				<ul>
					<li>
						<div class="buttonActive">
							<div class="buttonContent">
								<button type="submit" onclick="initCurrentPage()">查询</button>
							</div>
						</div>
					</li>
				</ul>
			</div>
		</div>
	</form>
</div>

<form method="post" action="makeCardBlank/exportTaskSingle"
	class="pageForm required-validate"
	onsubmit="return commitFormExportTaskSingle(this);">
	<div class="pageContent">
		<div class="panelBar">
			<ul class="toolBar">
				<!-- <li><a class="add" href="makeCardBlank/addMakeCardTask" target="dialog" rel="MakeCardTask"><span>添加</span></a></li> -->
				<li><a class="delete" onclick="return deleteSingleTask();"><span>删除</span></a></li>
				<li><a class="edit" onclick="return updateSingleTask();"><span>修改</span></a></li>
			</ul>
		</div>
		<!-- <input name="singletasked" type="checkbox" style="display:none" value="xxxxxxxxxxx" checked> -->
		<div id="ByMakeCardSingle">
			<table class="table" width="100%" layoutH="298">
				<thead>
					<tr align="center">
						<th width="2%"><input type="checkbox" name=""
							group="singletasked" onclick="checkAllSave(this)"
							class="checkboxCtrl"></th>
						<th width="17%">任务编号</th>
						<th width="15%">任务名称</th>
						<th width="13%">卡产品</th>
						<th width="15%">卡物理类型</th>
						<th width="5%" class="asc"
							onclick="order($('#tbodySingleTask'),5)">数量</th>
						<th width="10%">任务生成日期</th>
						<th width="15%">网点</th>
						<th width="8%">备注(是否加急)</th>
					</tr>
				</thead>
				<tbody id="tbodySingleTask">

				</tbody>
			</table>
		</div>
		<!-- <div class="panelBar">
		<div class="pages">
			<span>显示</span>
			<select id="numPerPageBySingleTask" name="numPerPage" onchange="paging(this,$('#getSingleMakeCardInfo'),getSingleTaskInfo)">
				<option value="20">20</option>
				<option value="30">30</option>
				<option value="50">50</option>
				<option value="100">100</option>
			</select>
			<span id="totalCountBySingleTask"></span>
		</div>
			<div id="paginationBySingleTask" class="pagination1"  ></div>
	</div> -->
		<div class="panelBar">
			<div class="pages">
				<span>显示</span> <select class="combox" name="numPerPage"
					onchange="navTabPageBreak({numPerPage:this.value},'tbodySingleTask',getSingleTaskInfo)">
					<option value="20">20</option>
					<option value="50">50</option>
					<option value="100">100</option>
					<option value="200">200</option>
				</select> <span id="totalCountBySingleTask">条，共${totalCount}条</span>
			</div>

			<div callback='getSingleTaskInfo' id="paginationBySingleTask"
				rel="tbodySingleTask" class="pagination" targetType="navTab"
				totalCount="200" numPerPage="5" pageNumShown="5" currentPage="1"></div>

		</div>
		<!-- <div class="pageContent"></div> -->
		<div class="formBar">
			<ul>
				<li>
					<div class="buttonActive">
						<div class="buttonContent">
							<button type="submit" onclick="return validateChechBox3();">导出</button>
						</div>
					</div>
				</li>
			</ul>
		</div>

	</div>
</form>


